function isWin(Map){
    let XNum = 0;
    let ONum = 0;
    for (let i = 0; i < 9; ++i){
        if (Map[i] === 1) ++XNum;
        else if (Map[i] === 2) ++ONum;
    }

    let nowStep = XNum > ONum ? 1 : 2;

    if(Map[0] === nowStep && Map[4] === nowStep && Map[8] === nowStep){
        return true;
    }

    if (Map[2] === nowStep && Map[4] === nowStep && Map[6] === nowStep){
        return true;
    }

    for (let i = 0; i < 3; ++i){
        if (Map[3*i] === nowStep && Map[1+3*i] === nowStep && Map[2+3*i] === nowStep) return true;
    }

    for (let i = 0; i < 3; ++i){
        if (Map[0+i] === nowStep && Map[3+i] === nowStep && Map[6+i] === nowStep) return true;
    }

    return false;
}

function full(Map){
    let XNum = 0;
    let ONum = 0;
    for (let i = 0; i < 9; ++i){
        if (Map[i] === 1) ++XNum;
        else if (Map[i] === 2) ++ONum;
    }
    return XNum+ONum === 9;
}

function getNowStep(Map){
    let XNum = 0;
    let ONum = 0;
    for (let i = 0; i < 9; ++i){
        if (Map[i] === 1) ++XNum;
        else if (Map[i] === 2) ++ONum;
    }
    return XNum > ONum ? 1 : 2;
}

export {
    getNowStep,
    isWin,
    full
}